package main

import (
	"Gin-Server-01/com/server/common"
	"Gin-Server-01/com/server/core/pojo"
	"Gin-Server-01/com/server/core/tools/jsonTool"
	"Gin-Server-01/com/server/core/tools/redisPoolTool"
	"fmt"
	"github.com/go-redis/redis/v8"
	"time"
)

type User struct {
	Id        uint
	Name      string
	BankCards []BankCard
}

type BankCard struct {
	Account  string
	Password string
	Balance  float32
}

func main() {

	all, _ := redisPoolTool.HGetAll("Chat:InBox_toID:11:fromID:")
	if all == nil {
		for _, o := range all {
			fmt.Println(o)

		}
	}
	insertList := []pojo.ChatPayload{}

	temoPayload := pojo.ChatPayload{
		MessageID:   1,
		SenderID:    2,
		ReceiverID:  0,
		Content:     "1",
		Timestamp:   "2",
		MessageType: "3",
		IsRead:      false,
	}
	insertList = append(insertList, temoPayload)
	insertList = append(insertList, temoPayload, temoPayload)
	fmt.Println(insertList)

	for _, payload := range insertList {
		fmt.Println(payload)

	}
	fmt.Println()
	fmt.Println()
	fmt.Println(insertList)

	//no2()

}

var z = redis.Z{
	Score:  100,
	Member: 11,
}

// no3
//
//	@Summary:
//	@Description: ZSET
func no3() {
	redisPoolTool.ZAdd("KEY", &z)
	zRange, _ := redisPoolTool.ZRange("KEY", 0, 2)
	fmt.Println(zRange)
	redisPoolTool.ZRem("KEY", 11)

	z.Member = (z.Member.(int)) + 1
	redisPoolTool.ZAdd("KEY", &z)

	z.Member = (z.Member.(int)) + 1
	redisPoolTool.ZAdd("KEY", &z)

}
func no2() {
	var payloads []pojo.ChatPayload
	var payload = pojo.ChatPayload{}
	all, _ := redisPoolTool.HGetAll("Chat:OutBox_fromID:12:toID:")
	for _, obj := range all {
		fmt.Println("怎么办?" + obj)

		jsonTool.JSONToStruct(obj, &payload)

		fmt.Println("转换2:>>>>>>>>>>>>>>>>>>", payload)
		payloads = append(payloads, payload)

	}

	fmt.Println("==========")
	fmt.Println(payloads)

}

func no1() {
	user := User{
		Id:   0,
		Name: "薛智敏",
		BankCards: []BankCard{
			{
				Account:  "1001",
				Password: "1111",
				Balance:  780,
			},
			{
				Account:  "2002",
				Password: "xzm.222",
				Balance:  1000,
			},

			{
				Account:  "张山",
				Password: "zhangshan1234",
				Balance:  80001,
			},
		},
	}
	err := redisPoolTool.SetKeyWithExpire("key", common.Object{}.JsonStringImpl(user), time.Second*8)

	if err != nil {
		fmt.Println("错误")
	}

	key, _ := redisPoolTool.GetKey("key")

	u := User{}

	jsonTool.JSONToStruct(key, &u)
	fmt.Println(u)

}
